<?php
/**
 * Created by PhpStorm.
 * User: jieai
 * Date: 2017-04-03
 * Time: 10:02
 */
namespace Home\Controller;

use Think\Controller;

class MemberController extends MyController
{
    public function index()
    {
        $this->display();
    }

    public function getMembers()
    {
        $result = M('member')->select();
        return $this->ajaxReturn($result);
    }

    public function member_post()
    {
        $this->Checklogin();
        if (IS_AJAX) {
            $result=null;
            $member = M('member');
            $id = I('id');
            $member->name = I('name');
            $member->cardnum = I('cardnum');
            $member->phonenum = I('phonenum');
            $member->remarks = I('remarks');
            if ($id) {//id不为空,修改

                $member->id = $id;
                 $result= $member->save();

            }
            else{
               $result=  $member->add();
            }
            $result?$this->ajr():$this->ajr("",0);
        }


    }

    public function member_delete()
    {
        $this->Checklogin();

        if (IS_AJAX) {
            $result=M('member')->delete(I('id'));
            if ($result) {
                $this->success('删除成功');
            }else{
                $this->success('删除失败');
            }

        }
    }
}